/*
 * @Author: CodeHare
 * @Date: 2023-09-19 18:46:23
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-03-04 19:02:14
 * @Description: 自研EMS远程设置
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/ems/self_develop_ems_romote_control/ems_romote_control/ems_romote_control_controller.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/ems/common/common_widget.dart';

class EmsRomoteControlPage extends GetView<EmsRomoteControlController> {
  const EmsRomoteControlPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EmsRomoteControlController>(
      builder: (_) => Scaffold(
        appBar: AppBarWidget.defaultAppBar('siteMonitor.remoteControl'.tr),
        body: Column(
          children: <Widget>[
            Expanded(
              child: ListView.separated(
                itemBuilder: (context, index) {
                  final item = controller.emsRomoteControlList[index];
                  final length = controller.emsRomoteControlList.length;
                  final lastIndex = length - 1;

                  /// 标题
                  if (index == 0) {
                    return SelfDevEmsControlCommon.createHeader(item);
                  }

                  /// 系统复位
                  if (index != lastIndex) {
                    final RadioSwitchParams radioParams = RadioSwitchParams(
                      context: context,
                      item: item,
                      enabled: item.enabled,
                      onTap: controller.clickRadio,
                      index: index,
                      status: controller.connectStatus!,
                    );

                    return SelfDevEmsControlCommon.createRadio(radioParams);
                  }

                  /// 其余列表
                  final RadioSwitchParams switchParams = RadioSwitchParams(
                    context: context,
                    item: item,
                    enabled: controller.switchVal,
                    onTap: controller.changeSwitch,
                  );

                  return SelfDevEmsControlCommon.createSwitch(switchParams);
                },
                separatorBuilder: (BuildContext context, int index) =>
                    SelfDevEmsControlCommon.divider,
                itemCount: controller.emsRomoteControlList.length,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
